package com.wangjiyuan.giftshuo.ui.activity.classify.strategy_details.group_all_details;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;
import com.wangjiyuan.giftshuo.R;
import com.wangjiyuan.giftshuo.bean.classifybean.strategy.GroupBean;
import com.wangjiyuan.giftshuo.ui.activity.classify.strategy_details.group_details.GroupDetActivity;
import com.wangjiyuan.giftshuo.utils.RecyclerViewAdapterHelper;

import org.greenrobot.eventbus.EventBus;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.wangjiyuan.giftshuo.config.classify.ClassifyConstant.Strategy_MAP_ID;
import static com.wangjiyuan.giftshuo.config.classify.ClassifyConstant.Strategy_MAP_NAME;

/**
 * Created by QXL on 2016/11/20.
 */

public class StrDetAdapter extends RecyclerViewAdapterHelper<GroupBean.DataBean.ChannelGroupsBean.ChannelsBean> {
    public StrDetAdapter(Context context, List<GroupBean.DataBean.ChannelGroupsBean.ChannelsBean> list) {
        super(context, list);
    }

    @Override
    public RecyclerView.ViewHolder onCreateMyViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_strategy_details, parent, false);
        return new ViewHolderDetails(view);
    }

    @Override
    public void onBindMyViewHolder(RecyclerView.ViewHolder holder, int position) {
        int widthPixels = mContext.getResources().getDisplayMetrics().widthPixels;
        int heightPixels = mContext.getResources().getDisplayMetrics().heightPixels;
        GroupBean.DataBean.ChannelGroupsBean.ChannelsBean channelsBean = mList.get(position);
        Glide.with(mContext).load(channelsBean.getCoverImageUrl())
                .centerCrop()
                .into(((ViewHolderDetails)holder).imageView_StrDet);
        ((ViewHolderDetails) holder).imageView_StrDet.setLayoutParams(new LinearLayout.LayoutParams(widthPixels/2,heightPixels/9));
    }

    class ViewHolderDetails extends RecyclerView.ViewHolder implements View.OnClickListener{
        ImageView imageView_StrDet;
        public ViewHolderDetails(View itemView) {
            super(itemView);
            imageView_StrDet= (ImageView) itemView.findViewById(R.id.imageView_item_Strategy_Details);
            imageView_StrDet.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            Map<String,String> map;
            switch (v.getId()){
                case R.id.imageView_item_Strategy_Details:
                    Intent intent=new Intent(mContext, GroupDetActivity.class);
                    mContext.startActivity(intent);
                    GroupBean.DataBean.ChannelGroupsBean.ChannelsBean channelsBean = mList.get(getAdapterPosition());
                    String name = channelsBean.getName();
                    int ID = channelsBean.getId();
                    map=new HashMap<>();
                    map.put(Strategy_MAP_NAME,name);
                    map.put(Strategy_MAP_ID,ID+"");
//                    粘性的eventBus传值
                    EventBus.getDefault().postSticky(map);
                    break;
            }
        }
    }
}
